@@ -1,10 +1,20 @@ |
||
| 1 | 1 |
module LiquidInterpolatable |
| 2 | 2 |
extend ActiveSupport::Concern |
| 3 | 3 |
|
| 4 |
+ included do |
|
| 5 |
+ validate :validate_interpolation |
|
| 6 |
+ end |
|
| 7 |
+ |
|
| 4 | 8 |
def valid?(context = nil) |
| 5 | 9 |
super |
| 10 |
+ rescue Liquid::Error |
|
| 11 |
+ errors.empty? |
|
| 12 |
+ end |
|
| 13 |
+ |
|
| 14 |
+ def validate_interpolation |
|
| 15 |
+ interpolated |
|
| 6 | 16 |
rescue Liquid::Error => e |
| 7 |
- errors.add(:base, e.message) |
|
| 17 |
+ errors.add(:options, "has an error with Liquid templating: #{e.message}")
|
|
| 8 | 18 |
false |
| 9 | 19 |
end |
| 10 | 20 |
|
@@ -29,7 +29,7 @@ describe LiquidInterpolatable::Filters do |
||
| 29 | 29 |
it "should finish without raising an exception" do |
| 30 | 30 |
agent = Agents::InterpolatableAgent.new(name: "test", options: { 'foo' => '{{bar}' })
|
| 31 | 31 |
agent.valid?.should == false |
| 32 |
- agent.errors[:base].first.should =~ /not properly terminated/ |
|
| 32 |
+ agent.errors[:options].first.should =~ /not properly terminated/ |
|
| 33 | 33 |
end |
| 34 | 34 |
end |
| 35 | 35 |
end |